﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Dracham.Classes
{
    public class Utility
    {
        private static Random random = new Random(DateTime.Now.Millisecond * DateTime.Now.Second);

        public static double RandomDouble()
        {
            return random.NextDouble();
        }

        public static int Random(int max)
        {
            if (max < 0)
                return 0;

            return random.Next(max);
        }

        public static int Random(int min, int max)
        {
            if ( min == max )
                return min;

            if (max < 0)
                return 0;

            return random.Next(min, max);
        }

        public static int Random(float min, float max)
        {
            return Utility.Random((int)min, (int)max);
        }

        public static String GetMd5Hash(String text)
        {
            MD5CryptoServiceProvider hashService = new MD5CryptoServiceProvider();

            Byte[] hashedBytes = hashService.ComputeHash(Encoding.UTF8.GetBytes(text));
            
            StringBuilder sb = new StringBuilder();

            foreach (Byte b in hashedBytes)
            {
                sb.Append(b.ToString("X2"));
            }

            return sb.ToString();
        }
    }
}
